//
//  ZhaungshiViewController.m
//  制作图标
//
//  Created by mac on 2017/8/23.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#import "ZhaungshiViewController.h"
#import "BackGroundCVCell.h"
@interface ZhaungshiViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation ZhaungshiViewController
static NSString *cellIdentyfier = @"backcell";
- (void)viewDidLoad {
    [super viewDidLoad];
    //    1.创建布局（横向布局、纵向布局）
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    layout.minimumLineSpacing = 1.0;
    //    2.创建集合视图，设置代理
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.dataSource =self;
    self.collectionView.delegate = self;
    //    3.注册单元格（item）
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:cellIdentyfier];
    //    4.加载视图
    [self.view addSubview:self.collectionView];
    //      加载nib文件
    [self.collectionView registerNib:[UINib nibWithNibName:@"BackGround" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:cellIdentyfier];

}
#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 30;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    BackGroundCVCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentyfier forIndexPath:indexPath];
    cell.imageView0.image = [UIImage imageNamed:[NSString stringWithFormat:@"deco_%ld",(long)indexPath.row +1 ]];
    // Configure the cell
    
    return cell;
}
#pragma mark -- UICollectionViewDelegateFlowLayout
/** 每个cell的尺寸*/
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(80, 80);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"deco_%ld",(long)indexPath.row +1 ]];
    if (self.returnValueBlock) {
        self.returnValueBlock(image);
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
